from django.test import TestCase
from django.test.client import Client

"""
Testira stranu sa vestima
"""
class NewsTestCase(TestCase):
    
    def setUp(self):
        pass

    def runTest(self):
        self.runAllNewsTest()
        self.runOneNewsTest()

    def runAllNewsTest(self):
        c = Client()
        c.login(username='kokan', password='123')
        
        response = c.get("/mdcs/news/")
        self.failIf(response == None)
        self.failIf(response.context == None)
        self.failUnlessEqual(len(response.context), 5)
        self.failIf(response.context[0]["news"] == None)
        
        news = response.context[0]["news"]
        self.failUnlessEqual(len(news.object_list), 2)
        
        self.failUnlessEqual(news.object_list[0].id, 2)
        self.failUnlessEqual(news.object_list[0].news_title, 'Druga vest')
        self.failUnlessEqual(news.object_list[1].id, 1)
        self.failUnlessEqual(news.object_list[1].news_title, 'Prva vest')

    def runOneNewsTest(self):
        c = Client()
        c.login(username='kokan', password='123')
        
        response = c.get("/mdcs/news/1/")
        self.failIf(response == None)
        self.failIf(response.context == None)
        self.failUnlessEqual(len(response.context), 3)
        self.failIf(response.context[0]["one_news"] == None)
        
        one_news = response.context[0]["one_news"]
        self.failUnlessEqual(one_news.id, 1)
        self.failUnlessEqual(one_news.news_title, 'Prva vest')